package 面向对象初级.HomeWork;

public class CommonsTools {
    /**
     * 7、常识工具类
     * 案例：
     * 声明一个常识工具类CommonsTools，包含如下方法：
     * 1、String getWeekName(int week)：根据星期值，返回对应的英语单词
     * 2、String getMonthName(int month)：根据月份值，返回对应的英语单词
     * 3、int getTotalDaysOfMonth(int year, int month)：返回某年某月的总天数
     * 4、int getTotalDaysOfYear(int year)：获取某年的总天数
     * 5、boolean isLeapYear(int year)：判断某年是否是闰年
     * 声明一个Test08测试类，并在main方法中调用测试
     */
    // 根据星期值，返回对应的英语单词
    public static String getWeekName(int week) {
        String[] weekNames = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
        if (week < 1 || week > 7) {
            throw new IllegalArgumentException("Invalid week value");
        }
        return weekNames[week - 1];
    }

    // 根据月份值，返回对应的英语单词
    public static String getMonthName(int month) {
        String[] monthNames = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
        if (month < 1 || month > 12) {
            throw new IllegalArgumentException("Invalid month value");
        }
        return monthNames[month - 1];
    }

    // 返回某年某月的总天数
    public static int getTotalDaysOfMonth(int year, int month) {
        if (month == 2) {
            if (isLeapYear(year)) {
                return 29;
            } else {
                return 28;
            }
        } else if (month == 4 || month == 6 || month == 9 || month == 11) {
            return 30;
        } else {
            return 31;
        }
    }

    // 获取某年的总天数
    public static int getTotalDaysOfYear(int year) {
        if (isLeapYear(year)) {
            return 366;
        } else {
            return 365;
        }
    }

    // 判断某年是否是闰年
    public static boolean isLeapYear(int year) {
        return (year % 4 == 0 && year % 100!= 0) || year % 400 == 0;
    }
}
